//
// Score.cpp for nibbler in /home/lefebv_w//workspace/cpp/nibbler/googleCode
// 
// Made by damien lefebvre
// Login   <lefebv_w@epitech.net>
// 
// Started on  Tue Mar 19 15:58:38 2013 damien lefebvre
// Last update Fri Jul 26 17:37:38 2013 mickael gomes
//

#include	"Score.hh"

Score::Score(unsigned int pos_y, unsigned int value)
  : m_pos_y(pos_y), m_value(value), m_level(1), m_nbofpart(0), m_life(3), m_vitesse(6)
{
  vitesses.push_back(6);
  vitesses.push_back(5);
  vitesses.push_back(4);
  vitesses.push_back(3);
  vitesses.push_back(2);
  vitesses.push_back(1);
}

void		Score::draw(IGraphicLibrary & graph) const
{
  std::ostringstream	os;

  os << "Score : " << std::setfill('0') << std::setw(3) << m_value;
  os << "    Level : " << std::setfill('0') << std::setw(2) << m_level;
  os << "    Life : " << std::setfill('0') << std::setw(1) << m_life;
  graph.draw_footer(0, m_pos_y, os.str());
}

bool		Score::eat(unsigned int value)
{
  m_nbofpart += value;
  m_value += value;
  if (m_nbofpart % 10 == 0)
    {
      levelUp();
      return (true);
    }
  return (false);
}

bool		Score::add(unsigned int value)
{
  m_value += value;
}

void		Score::levelUp(void)
{
  m_level++;
  if (m_level < vitesses.size())
    m_vitesse = vitesses[m_level - 1];
}

unsigned int   	Score::getLevel(void) const
{
  return (m_level);
}

unsigned int   	Score::getLife(void) const
{
  return (m_life);
}

unsigned int	Score::loseLife(void)
{
  m_life--;
  return (m_life);
}

void		Score::addLife(void)
{
  m_life++;
}

t_frame		Score::getVitesse(void) const
{
  return (m_vitesse);
}
